package D240607;

public class SynchronizedTest {

    public static void main(String[] args) {
        Object o = new Object();
        Object o1 = new Object();

        new Thread(() -> {
            synchronized (o) {
                System.out.println(1);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (o1){
                    System.out.println(2);
                }
            }

        }).start();

        new Thread(() -> {
            synchronized (o1){
                System.out.println(2);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (o) {
                    System.out.println(1);
                }
            }

        }).start();
    }
}
